package engine.newUi
{
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.ResPath;
	import engine.data.RoleVo;
	import engine.flag.ResourcesPath;
	import engine.logic.LogSendLogic;
	import engine.logic.event.LogicEvent;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.scene.SceneManager;
	import engine.scene.player.MoveAction;
	import engine.tip.TipsMainLogic;
	
	import fl.motion.ColorMatrix;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.GlowFilter;
	import flash.text.TextFormat;
	
	import flashx.textLayout.container.ScrollPolicy;
	
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.button.NxButton;
	import newx.com.control.group.NxViewGroup;
	import newx.com.control.text.NxLabel;
	import newx.com.control.text.NxText;
	import newx.com.control.window.NxWindowEvent;
	

	/**
	 * 
	 * @author yangcg 活动
	 * 
	 */	
	public class ActionFaceplateLogic
	{
		public static var _self:ActionFaceplateLogic; 
		public static function getInstance():ActionFaceplateLogic
		{
			if(_self==null)
			{
				_self = new ActionFaceplateLogic(); 
				
			}
			return _self
		}
		public function get ui():ActionFaceplateUI 
		{
			return _ui;
		}
		private var _ui:ActionFaceplateUI ; 
		/***最大页数**/
		private var _pageMax:uint ; 
		/***最小页数**/
		private var _pagemin:uint =1 ; 
		/**当前页数***/
		private var _indexPage:int = 1; 
		/*****/
		private var _role:RoleVo; 
		/*****/
		private var _model:ModelLocator; 
		/**当前你所选择活动*/
		private var _choose:uint ; 
		/****/
		private var _indexOneCount:int=-1; 
		/******/
		private var _bingManage:BindManage;
		/**数据数组*/
		private var _arrList:Array=[]; 
		/**显示数据*/
		private var _arrInfo:Array=[];
		/**id，名字，特效，组号*/
		private var _arrLength:int = 4;
		/**记录当前选中组号*/
		private var _currNum:int;
		/**记录当前选中**/
		private var _newIndex:int;
		/**记录上次选中**/
		private var _oldIndex:int;
		/***初始化记载**/
		private var _indexCount:int
		/**按钮个数**/
		private var _btnNum:int = 5;
		/****/
		private var _itemMc:MovieClip;
		private var _group:NxViewGroup;
		/***当前选中的按钮**/
		private var _btnMC:MovieClip ; 
		/**-1 0 1**/
		private var _isOK:int  = 0 ; 
		private var _oneIndex:int = -1; 
		/***/
		private var _firstOver:int  = -1;  
		
		private var ld_Matrix:ColorMatrix=new ColorMatrix(); 
		private var ld_Filter:ColorMatrixFilter=new ColorMatrixFilter(); 
		/***记录按钮当前状态***/
		private const ONE:int=1,TWO:int=2,THREE:int=3;
		/***缓存状态**/
		private var Five:int  = 0 ;
		/**显示奖品组件的列数**/
		private const COL:int = 5  ; 
		/***奖品盛放格子 动态创建***/
		private var viewGroup:NxViewGroup = new NxViewGroup(); 
		private var row:int = 0 ; 
		public function ActionFaceplateLogic()
		{
			
		}
		public function Init():void
		{
			ld_Matrix.SetBrightnessMatrix(40);  
			ld_Filter.matrix = ld_Matrix.GetFlatArray(); 
			
			_ui = ActionFaceplateUI.getIntence();
			_model= ModelLocator.getInstance();
			_role=_model.scene.Role;
			_bingManage=BindManage.getInstance(); 
			
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FESTALACTIVITY_LIST),showlist)
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_FESTALACTIVITY_INFO),showInfo)
			_ui.text.wordWrap=true; 
			_group = _ui.btn;
			
			viewGroup.x = 290;
			viewGroup.y = 307 ; 
			
			setPoint(_ui.text);
			setPoint(_ui.getAward);
			setPoint(_ui.activitytime);
			setPoint(viewGroup);
			setPoint(_ui.Image);
			
			setPoint(_ui.image_1);
			setPoint(_ui.image_2);
			setPoint(_ui.image_3);
			
			
			_ui.nxPanel.addView(_ui.image_1)
			_ui.nxPanel.addView(_ui.image_2)
			_ui.nxPanel.addView(_ui.image_3)
				
			_ui.nxPanel.addView(_ui.Image)
			_ui.nxPanel.addView(_ui.text)
			_ui.nxPanel.addView(_ui.getAward)
			_ui.nxPanel.addView(_ui.activitytime)
			_ui.nxPanel.addView(viewGroup);
			_ui.nxPanel.autoScroll =false ; 
//			_ui.nxPanel.verticalScrollPolicy	=	ScrollPolicy.AUTO;
//			_ui.nxPanel.horizontalScrollPolicy	=	ScrollPolicy.OFF;
			
			_ui.nxPanel.viewWidth   = 	442 ;
			_ui.nxPanel.viewHeight  = 	375	; 
			_ui.nxPanel.width		=	442	; 
			_ui.nxPanel.height		=	375 ;
//			_ui.nxPanel.vscroll = 0
//			_ui.nxPanel.hscroll = 0;
			_oneIndex = _bingManage.BindProp(_model.scene.Role ,"RewardCount" ,this, "getRewardCount");
//			_ui.text.verticalScrollPolicy = ScrollPolicy.AUTO; 

		}
		public function BeforeShow():void
		{
			awardInfo();
			
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FESTALACTIVITY_LIST);
			_firstOver = -1 ; 
			_currNum = 1;
			_oldIndex = -1;
			_indexCount =-1;
			_newIndex = 0;
			PageBtn();
			addLintener();
			
			_ui.text.setTextFormat(setTextFormat(0x017b26))
			_ui.text.glowColor=0xf6f1e1;
			
			ui.activitytime.setTextFormat(setTextFormat(0x983f00));
			_ui.getAward.setTextFormat(setTextFormat(0x983f00));
			_ui.activitytime.glowColor=0xf6f1e1;
			_ui.getAward.glowColor=0xf6f1e1;

			
			((ui["btn"] as NxViewGroup).getItemByIndex(0) as MovieClip).gotoAndStop(2);
			for(var j:uint  = 0; j< _btnNum ; j++)
			{
				_itemMc = (ui["btn"] as NxViewGroup).getItemByIndex(j);
				_itemMc.visible = false;
				_itemMc["txt"].mouseEnabled = false;

				_itemMc.gotoAndStop(1);
				
			}
			_ui.nxPanel.vscroll = 0;
			
			if(!SceneManager._itemIconLoad)
			{
				_model.addEventListener(LogicEvent.ITEMICONLOADED,loaded);
				function loaded():void
				{
					
					clearArrBtn();
					clearArrLabel();
					clearArrLine(); 
					
					if(arr_ID==null)return ; 
					arr_ID[int(_currNum-1)]// 这一组 所有的ID
//					arr_obj[_currNum]
					SystemSender.getInstance().CustomMsgEx(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FESTALACTIVITY_INFO,arr_ID[int(_currNum-1)]);
					_model.removeEventListener(LogicEvent.ITEMICONLOADED,loaded)
				}
			}
			//初始化多余的 格子----临时用
			
			_ui.image_1.source = ResPath.PNG +"huodongshijian.png" ; 
			_ui.image_2.source = ResPath.PNG +"lingjiangshijian.png" ; 
			_ui.image_3.source = ResPath.PNG +"huodongmiaoshu.png" ; 
				
		}
		/**
		 * 获取组件皮肤~和位置
		 */
		private function getSKinAndPoint():void
		{
			var count:uint  =viewGroup.row*viewGroup.col; 
			var i :uint  =0  ; 
			for(i;i<count;i++)
			{
				var itemMC:MovieClip=viewGroup.getItemByIndex(i);
				itemMC.gotoAndStop(1);
				var Image:NxClip= new NxClip(); 
				var label:NxLabel = new NxLabel();
				label.color = 0xffffff ; 
				label.x = 32;
				label.y =25 ;
				Image.isCache = true ; 
				itemMC["img2"].addChild(Image) ; 
				itemMC["image"] = Image ; 
				itemMC["label"] = label ; 
				itemMC["img2"].addChild(label) ;
			}
		}
		/**
		 *设置组件在容器的位置 
		 */		
		private function setPoint(value:*):void
		{
			 value.x = value.x  - _ui.nxPanel.x
			 value.y = value.y  - _ui.nxPanel.y 
		}
		/**
		 * 
		 * 关闭页面所要 清空的数据
		 */		
		public function AfterHide():void
		{
			_indexPage =1;  
			removeLintener();
			_ui.activitytime.filters=[];
			_ui.text.filters=[];
			_ui.getAward.filters=[];
			Clearinfo();
			clearArrBtn();
			clearArrLabel();
			clearArrLine();
			ClearItem(); 
			arr_obj = null ; 
			_btnMC = null ;
			currMC = null ;
		}
		/**
		 * 
		 * 
		 */
		private function Clearinfo():void
		{
			_ui.Image.source="";
			_ui.activitytime.htmlText = "";
			_ui.getAward.htmlText = "";
			_ui.text.htmlText =""
//			_ui.label_2.htmlText =""
			_ui.label_page.htmlText="";
			
			
//			var count:uint  = _ui.item.row*_ui.item.col; 
//			var j :uint  =0  ; 	
//			for(j;j<count;j++)
//			{
//				var itemMC:MovieClip=_ui.item.getItemByIndex(j);
//				itemMC["image"].source = null;
//				itemMC["image"] = null;
//				itemMC["label"].text = "";
//			}
			for(var i:int = 0;i < _btnNum;i++){
				_itemMc = _group.getItemByIndex(i);
				_itemMc.visible = false;
			}
		}
		private function addLintener():void
		{
			_ui.leftBtn.addEventListener(MouseEvent.CLICK,leftBtnHandler);
			_ui.rightBtn.addEventListener(MouseEvent.CLICK,rightBtnHandler);
			_ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,closeHandler);
			_ui.money.addEventListener(MouseEvent.CLICK,moneyHandler);
			for(var i:int = 0;i < _btnNum;i++){
				_itemMc = _group.getItemByIndex(i);
				_itemMc.addEventListener(MouseEvent.MOUSE_OVER, overHandler);
				_itemMc.addEventListener(MouseEvent.MOUSE_OUT, outHandler);
			}
			_ui.btn.addItemsEvent(MouseEvent.CLICK , ClickHandler);

//			addOverTips(_ui.item)
			
		}
		private function removeLintener():void
		{
			_ui.leftBtn.removeEventListener(MouseEvent.CLICK,leftBtnHandler);
			_ui.rightBtn.removeEventListener(MouseEvent.CLICK,rightBtnHandler);
			_ui.money.removeEventListener(MouseEvent.CLICK,moneyHandler);
			_ui.windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE,closeHandler);
			for(var i:int = 0;i < _btnNum;i++){
				_itemMc = _group.getItemByIndex(i);
				_itemMc.removeEventListener(MouseEvent.MOUSE_OVER, overHandler);
				_itemMc.removeEventListener(MouseEvent.MOUSE_OUT, outHandler);
			}

//			removeOverTips(_ui.item);
		}
		private var currMC:MovieClip ; 
		private function ClickHandler(e:MouseEvent):void
		{
			
			var btn:MovieClip  = e.currentTarget as MovieClip;
			if(	_currNum == btn["num"]){
				btn.gotoAndStop(2);
				Five	=	btn["state"];
				currMC  = 	btn 
				return ; 
			}
			
			_choose = btn["confid"];
			_currNum = btn["num"]; //组号
			
			clearArrBtn();
			clearArrLabel();
			clearArrLine() ;
		
			btn.gotoAndStop(2) ; 
			if(currMC==btn)return ; 
			if(currMC==null)
			{
				Five	=	btn["state"];
				currMC  = 	btn 
			}else
			{
				Five	=	currMC["state"]; 
				currMC.gotoAndStop(Five) ;
				currMC  = 	btn 	
			}
			

			
			arr_ID[int(_currNum-1)]// 这一组 所有的ID
//			arr_obj[_currNum]
			SystemSender.getInstance().CustomMsgEx(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FESTALACTIVITY_INFO,arr_ID[int(_currNum-1)]);
			
		}
		/***按钮**/
		private function addOverBtn(btn:DisplayObject):void
		{
			btn.addEventListener(MouseEvent.MOUSE_OVER,overHandler);
			btn.addEventListener(MouseEvent.MOUSE_OUT ,outHandler);
		}
		/***释放按钮监听***/
		private function removeOverBtn(btn:DisplayObject):void
		{
			btn.removeEventListener(MouseEvent.MOUSE_OVER,overHandler);
			btn.removeEventListener(MouseEvent.MOUSE_OUT ,outHandler);
		}
		/**图片的TIPS***/
		private function addOverTips(btn:NxViewGroup):void
		{
			btn.addItemsEvent(MouseEvent.MOUSE_OVER,overTipsHandler);
			btn.addItemsEvent(MouseEvent.MOUSE_OUT ,outTipsHandler);
		}
		/**释放 Tips监听**/
		private function removeOverTips(btn:NxViewGroup):void
		{
			btn.removeItemsEvent(MouseEvent.MOUSE_OVER,overTipsHandler);
			btn.removeItemsEvent(MouseEvent.MOUSE_OUT ,overTipsHandler);
		}
		private function leftBtnHandler(e:MouseEvent):void
		{
			
			_indexPage--; 
			if(_indexPage<=0)
			{
				_indexPage=1;
			}
				
			if(_indexPage<=_pagemin)
			{
				_indexPage =_pagemin; 
				_ui.leftBtn.enabled=false ; 
			}
			_ui.rightBtn.enabled= true ; 
			
			
			_isOK = -1; 
			_oldIndex = -1 ; 
			currMC=null
			IntiUI(_indexPage)
			
//			for(var i :int = 0; i<arrLabel.length ; i++)
//			{
//				_ui.windowBG.removeChild(arrLabel[i]);
//			}
		}
		private function rightBtnHandler(e:MouseEvent):void
		{
//			_firstOver = 0 ; 
			_indexPage++ ;
			if(_indexPage>=_pageMax)
			{
				_indexPage = _pageMax;
				_ui.rightBtn.enabled =false ; 
			}
			_ui.leftBtn.enabled=true ; 

			_isOK = 1; 
			_oldIndex = -1 ; 
			currMC=null;
			IntiUI(_indexPage)
			
//			for(var i :int = 0; i<arrLabel.length ; i++)
//			{
//				_ui.windowBG.removeChild(arrLabel[i]);
//			}
		}
		
		/**
		 *鼠标移上去 
		 * @param e
		 * 
		 */		
		private function overHandler(e:MouseEvent):void
		{
			var btn:MovieClip  = e.currentTarget as MovieClip;
			btn.filters = [ld_Filter] ;
//			_choose = btn["confid"];
//			_currNum = btn["num"];
//
//			
//			showSpecific((_group.getItemByIndex(0) as MovieClip)["isOk"],0);
//			
//			_newIndex = btn["index"];
//			if(_oldIndex != _newIndex){
//				btn.gotoAndStop(2);
//				if(_oldIndex > -1){
//					var item:MovieClip = _group.getItemByIndex(_oldIndex);
//					//检查是否完成
//					showSpecific(item["isOk"],_oldIndex);
//				}
//				_oldIndex = _newIndex;
//				_indexCount=_newIndex; 
//			}
//			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FESTALACTIVITY_INFO,_choose);
		}
		/**
		 *鼠标移除 
		 * @param e
		 * 
		 */		
		private function outHandler(e:MouseEvent):void
		{
			var btn:MovieClip  = e.currentTarget as MovieClip; 
			btn.filters = [] ;
//			TipsMainLogic.instance.hide(); 
		}
		/**
		 * 
		 * @param e 奖品的TIPS
		 * 
		 */
		private function overTipsHandler(e:MouseEvent):void
		{
			var item:MovieClip = e.currentTarget as MovieClip; 
			item["configid"] 
			TipsMainLogic.instance.showMain(item["configid"]);
		}
		/**
		 * 
		 * @param e
		 * 
		 */
		private function outTipsHandler(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide(); 
		}
		/**
		 *关闭窗口 
		 * @param e
		 * 
		 */		
		private function closeHandler(e:NxWindowEvent):void
		{
			_ui.showOrHide();
		}
		/**
		 * VIP充值
		 * @param e
		 * 
		 */		
		private function moneyHandler(e:MouseEvent):void
		{
			_role.recharge();
			LogSendLogic.getInstance().btnClickNumSend(22802)
		}
		/**
		 * 领取奖励
		 * @param e
		 * 
		 */		
		private function getAwardHandler(e:MouseEvent):void
		{

			var mc:NxButton = e.target  as NxButton ; 
			if(mc.data.GetProperties("ID")==-1)return  ;
			
			arr_ID[int(_currNum-1)]
	
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_REWARD,mc.data.GetProperties("ID"));
//			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_REWARD, mc["ID"]);
//			SystemSender.getInstance().CustomMsgEx(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FESTALACTIVITY_INFO,arr_ID[int(_currNum-1)]);
			
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FESTALACTIVITY_LIST);
			_isOK = 0 ; 
		}
		/**
		 *  显示奖品
		 * 
		 */
		private function awardInfo():void
		{
//			var count:uint  = _ui.item.row*_ui.item.col; 
//			var i :uint  =0  ; 
//			for(i;i<count;i++)
//			{
//				var itemMC:MovieClip=_ui.item.getItemByIndex(i);
//				itemMC.visible =false ; 
//				for(var j:int = 0 ; j<5 ;j++)
//				{
//					var itemAwardMC:MovieClip = itemMC["mc"]["mc_"+j]; 
//					itemAwardMC.gotoAndStop(1);
//					var Image:NxClip= new NxClip(); 
//					var label:NxLabel = new NxLabel();
//					label.color = 0xffffff ; 
//					label.x = 32;
//					label.y =25 ;
//					
//					Image.isCache = true ; 
//					itemAwardMC["img2"].addChild(Image) ; 
//					itemAwardMC["image"] = Image ; 
//					itemAwardMC["label"] = label ; 
//					itemAwardMC["img2"].addChild(label) ;
//					itemAwardMC.visible =false ;
					
//					itemAwardMC.addEventListener(MouseEvent.MOUSE_OVER,overTipsHandler);
//					itemAwardMC.addEventListener(MouseEvent.MOUSE_OUT ,outTipsHandler);
				
//				}
//				itemMC["btn_1"].addEventListener(MouseEvent.CLICK,getAwardHandler);

//			}
			
		}
		/**
		 *初始化 ------按钮给按钮副名字-----------------------
		 * value 当前第几页
		 */		
		private function IntiUI(value:uint):void
		{
			var j:uint = 0;
			for(j; j< _btnNum; j++)
			{
				_itemMc = _group.getItemByIndex(j);
				_itemMc.visible = false;
			}
//			var arrlist:Array = getArrList(_arrLength,_arrList);
			var arrlist:Array = _arrList;
			var arr:Array 	 =updatepageIndex(arrlist.length);
			_pageMax  = arr.length;
			if(_pageMax==1)
			{
				_ui.leftBtn.visible=false ; 
 				_ui.rightBtn.visible=false ; 
				
			}else
			{
				_ui.leftBtn.visible=true ; 
				_ui.rightBtn.visible=true ; 
				
			}
			_ui.label_page.htmlText = StaticIni.getSwfLangStrVar("UIString_1000504",[_indexPage.toString(),_pageMax]);
			var count:uint = uint(arr[value-1]);
			var i:uint = 0 ;
			for(i ; i < count; i++)
			{
				_itemMc = _group.getItemByIndex(i);
				_itemMc["txt"].htmlText = "<font color='#C1981A' size='13'><b>" 
																	+ arrlist[i+((value-1)*5)][1]+"</b></>";
				var textformat:TextFormat = new TextFormat();
				textformat.bold = true;
				_itemMc["txt"].setTextFormat(textformat);
				var glow:GlowFilter		= 	new GlowFilter();
				glow.color 				= 	0x283410;
				_itemMc["txt"].filters = [glow];
				_itemMc.name = "btn_"+i ;
				_itemMc["confid"]	= arrlist[i+((value-1)*5)][0];
				_itemMc["num"]		= arrlist[i+((value-1)*5)][3];
				_itemMc["index"]	= i;
				//是否按钮特效
				_itemMc["isOk"]		= arrlist[i+((value-1)*5)][2];
				_itemMc.visible = true ;
//				_itemMc.gotoAndStop(1);
				/**任务完成特效**/
				showSpecific(_itemMc["isOk"],i+(value-1)*5);
			}
			
		}
		/**
		 *任务完成显示特效 
		 * value 领奖状态
		 * 哪个按钮可以领奖
		 * awardArr
		 */		
		private function showSpecific(value:int,count:int):void  
		{
			_itemMc = _group.getItemByIndex(count%5);
			
			arr_ID[count]// 第一组   所有的ID 
//			arr_obj[count] ;
			for(var i:int =0 ; i<arr_ID[count].length ;i++)
			{
				for(var j:int = 0 ; j<infoArr.length ; j++)
				{
					if(arr_ID[count][i]==infoArr[j][0])
					{
						if(infoArr[j][2]>0)
						{
							_itemMc["state"] =THREE ;
							_itemMc.gotoAndStop(3);
							return ;
						}
					}
				}
				
			}
			_itemMc["state"] =ONE ;
			_itemMc.gotoAndStop(1);
			
			if(currMC != null)
			{
				if (currMC == _itemMc)
				{
					currMC.gotoAndStop(2);
				}
			}
			
			if(value>0)
			{
//				if(count ==_newIndex&&_indexCount!=-1&&_isOK==0)
//				{
//					_itemMc.gotoAndStop(2);
//				}else
//				{
//					if(_itemMc["over"]!=0)
//					{
//						_itemMc.gotoAndStop(3);
//					}else
//					{
//						_itemMc.gotoAndStop(1);
//					}
//					
//				}
//				
			}else
			{
				
//				_itemMc.gotoAndStop(1);
//				if(_indexCount!=-1)
//				{
//					if(count ==_newIndex&&_isOK==0)
//					{
//						_itemMc.gotoAndStop(2);
//					}
//				}
//				
			}
//			if(_firstOver==-1)
//			{
//				_firstOver = 0 ; 
//				var _itemMc1:MovieClip = _group.getItemByIndex(0);
//				_itemMc1.gotoAndStop(2);
//			}
			
		}
		/**
		 * 解析 服务器的数组
		 * @param e
		 * 
		 */
		private function getArrList(value:uint,arr:Array=null):Array
		{
			var i:uint = 0 ; 
			var arrlist:Array=[]; 
			for(i;i<(arr.length/value);i++)
			{
				arrlist.push([arr[(i*value)+0],arr[(i*value)+1],arr[(i*value)+2],arr[(i*value)+3]]);
			}
			return arrlist;
			
		}
		/**
		 * 模拟数据 按钮
		 * 
		 */	
		private var infoArr:Array; 
		private function showlist(e:CustomMsgEvent):void
		{
			if(_ui.created ==false ) return ; 
			
			_arrList=[];
			// 存所有的信息
			infoArr =[];
			
			var _tempArr:Array =e.pList;
//			
			if(_tempArr.length==0){
				_ui.leftBtn.visible=false ; 
				_ui.rightBtn.visible =false ; 
				_ui.label_2.htmlText="" ;
				
				Clearinfo();
				return ;
			}
			var arrlist:Array = getArrList(_arrLength,_tempArr);
			infoArr=arrlist  ; 
			setIDArr(arrlist);
			getArrListID(arrlist) ; 
					
			IntiUI(_indexPage);

			SystemSender.getInstance().CustomMsgEx(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_FESTALACTIVITY_INFO,arr_ID[_currNum-1]);
		}
		/**
		 * 设置相同 
		 *  这一组所有的ID
		 */		
		private var arr_ID:Array
		private var arr_obj:Object  ; 
		private function setIDArr(arr:Array):void
		{
			arr_obj = {}; 
			
			arr_ID = [] ; 
			var value_1:int = 0 ; 
			var litarr:Array =[] ; 
			var _numArr:Array = new Array();
			for(var i:int = 0;i<arr.length;i++){
				_numArr.push(arr[i][3]);
			}
			var _arr:Array = new Array();
			_arr = _numArr.concat();
			//			//按组号排序
			_arr.sort(Array.NUMERIC);
			
			for(var m:int  =0 ; m<_arr.length ;m++)
			{
				if(value_1!=_arr[m])
				{
					value_1=_arr[m]; 
					litarr.push(_arr[m])
				}
			}
			
			
			for(var k:int = 0;k<litarr.length;k++)
			{
				var value:int = litarr[k] ;
				var array:Array = [] ; 
				for(var j:int = 0;j<arr.length;j++)
				{
					if(arr[j][3] == value)
					{
						array.push(arr[j][0]);
					}
				}
				arr_ID.push(array) ; 
				//组号对应相应的 组里面任务ID 
				arr_obj[value] = array ; 
			}
		}
		/**
		 * 显示不同的活动 
		 */		
		private function getArrListID(arr:Array):void
		{
			var i :int = 0 ; 
			var value:int =0 ; 
			var array:Array = [] ; 
			arr.sort(function (arr_1:Array ,arr_2:Array):int
			{
				return arr_1[3] -arr_2[3] ; 
			}
				)
			for( i; i<arr.length ;i++)
			{
				if(value!=arr[i][3])
				{
					value=arr[i][3]; 
					_arrList.push(arr[i]);
				}
			}
		}
		/**
		 * 
		 * 
		 */		
		private function showInfo(e:CustomMsgEvent):void
		{
			_arrInfo=[];
			_arrInfo=e.pList;
			if(_arrInfo.length==0){
				return ; 
			}
			initInfo(1);
		}
		/**
		 *初始化翻页按钮 
		 */		
		private function PageBtn():void
		{
			_ui.leftBtn.enabled=false ; 
			_ui.rightBtn.enabled = true ;
		}
		/**
		 * 初始化活动信息
		 */	
		//奖品二维数组
		private var _awardArray:Array = new Array(); 
		private function initInfo(value:uint):void
		{	
			_awardArray =[]  ;
			AwardInfo(_arrInfo);
			/**时间数组**/
			getStr(awardArr[0]);
			
			
			var i :int = 0; 
			for(i;i<awardArr.length ; i++)
			{
				showAwardInfo(awardArr[i] ,i);
			}
			rowAndcol(_awardArray) ; 
			
			//下拉菜单
			_ui.nxPanel.viewHeight  = 	325;
//			_ui.nxPanel.viewHeight  = 	325+awardArr.length*50 ;
			
			
//			if(awardArr.length == viewGroup.row)
//			{
//				_ui.nxPanel.viewHeight  = 	325+viewGroup.row*50 ; 
//				
//			}else
//			{
				_ui.nxPanel.viewHeight  = 	325+viewGroup.height ;
				
//			}
			
//			_ui.nxPanel.vscroll = 0 ; 
			
			
			//每个活动的图片样式
			_ui.Image.source =  ResPath.JPG+awardArr[0][11]+".jpg";
			if(_ui.Image.source=="")
			{
				_ui.Image.source =  ResPath.JPG+"ActivityPic_"+0+".jpg";
			}
			_ui.text.htmlText =awardArr[0][9];
		
		}
		//记录绘制到第几行了
		private var countRow:int = 0 ;
		//存储 Label
		private var arrLabel:Array ;
		//存储 领取按钮
		private var arrBtn:Array ; 
		//存储线
		private var arrLine:Array ; 
		private function getRow():void
		{
			clearArrBtn();
			clearArrLabel();
			clearArrLine();
			
			arrLabel 	= [] ;
			arrBtn 		= [] ; 
			arrLine 	= [] ; 
			
			countRow = 0 ;
			var i :int = 0 ; 
			for(i; i<_awardArray.length; i++)
			{
				var num:int =  _awardArray[i].length/COL ; 
				var num_1:int = _awardArray[i].length%COL ; 
				if(num_1>0)
				{
					num+=1 ; 
				}
				//生成Label 并存储到 数组里面
				setNxlabel(_awardArray[i][0] as Object); 
				//生成Btn(领取按钮)并存储到 数组里面
				setNxButton(_awardArray[i][0] as Object ) ; 
				// 动态线
				setNxLine(num);
				//
				showArrAward(num,_awardArray[i].length,_awardArray[i]) ; 
			}
		}
		// 添加动态线
		private function setNxLine(value:int):void
		{
			var mcLine:MovieClip  = ResManager.newResClass("CustomControl_031")  as MovieClip ; 
			var mcLine_1:MovieClip  = ResManager.newResClass("CustomControl_031")  as MovieClip ; 
			
			mcLine.x = 0;
			mcLine.y = (305 -_ui.nxPanel.y)+ countRow*58; 
			
			mcLine_1.x = 0;
			mcLine_1.y = (300 -_ui.nxPanel.y)+ countRow*58+value*58; 
			
			_ui.nxPanel.addView(mcLine_1);
			_ui.nxPanel.addView(mcLine);
			setHeigt();
			arrLine.push(mcLine);
			arrLine.push(mcLine_1);
		}
		/**
		 * 
		 * @param value 奖品有几行
		 * @param count 奖品个数
		 * @param arr 奖品数组(x信息)
		 * 
		 */		
		//
		private function showArrAward(value:int ,count:int,arr:Array):void
		{
			
			var num:int = 0 ;
			var i:int =countRow*COL ; 
			for(i ; i <(value*COL)+(countRow*COL)  ; i++)
			{
				var mc:MovieClip = viewGroup.getItemByIndex(i);
				if(i<(countRow*COL)+count)
				{
					
					mc.visible = true  ; 
					var obj:Object = arr[num]  as Object;
					
					mc["id"]=obj["id"]
					mc["configid"]=obj["configid"]
					mc["labelX"]=obj["labelX"]
					mc["label"].text=obj["labeltext"]
					mc["image"].source=ResManager.newResClass(ResourcesPath.getPropsURL(int(obj["image"])));
					num++;
				}else
				{
					mc.visible =false ; 
				}
				mc.addEventListener(MouseEvent.MOUSE_OVER,overTipsHandler);
				mc.addEventListener(MouseEvent.MOUSE_OUT ,outTipsHandler);
			}
			countRow+=value;
		}
		/**
		 *  行列数
		 */	
		private function rowAndcol(arr:Array):void
		{
			
			row = 0 ; 
			viewGroup.viewSkin  ="Castle_Item_17" ;
			var i :int = 0 ; 
			for(i; i<_awardArray.length ; i++)
			{
				var value:int = _awardArray[i].length/5 ;
				var value_1:int = _awardArray[i].length%5 ;
				if(value_1>0)
				{
					value+=1;
				}
				row+=value ; 
			}
			viewGroup.row = row;  
			viewGroup.col = COL ; 
			viewGroup.offsetRow = 10 ;
			getSKinAndPoint();
			getRow();
		}
		/**
		 *  显示每个奖品
		 */	
		
		private function showAwardInfo(arr:Array,row:int):void
		{
			
			var strArr:Array = [] ;
			
			/**奖品个数*/
			var num:uint =(arr.length-12)/3;
			//领取按钮是否显示
//			showGain(arr[8] ,row);
			//每一行的组件
//			var itemMCAward:MovieClip=_ui.item.getItemByIndex(row);
//			itemMCAward.visible =true ; 
//			itemMCAward["titleTxt1"].text  = arr[10];
//			itemMCAward["ID"] = arr[0];
			
			
			
			
			var j:int =0  ; 
			for( j ; j<num ;j++)
			{
				if(j<num)
				{
					var _awardObj:Object ={} ; 
					_awardObj["BtnVisible"] = arr[8] ; 
					_awardObj["ID"]=arr[0];
					_awardObj["titleTxt1"]=arr[10];
					
					
					
					var _obj:Object=StaticIni.getIniObj(arr[(j*3)+13]);
					_awardObj["id"]=arr[(j*3)+12]
					_awardObj["configid"]=arr[(j*3)+13];
					_awardObj["labelX"]=34 -arr[(j*3)+14].toString().length*4;
					_awardObj["labeltext"]=arr[(j*3)+14] ; 
					_awardObj["image"]=int(_obj["Photo"]) ; 
//					ResManager.newResClass(ResourcesPath.getPropsURL(int(_obj["Photo"])));
					
					strArr.push(_awardObj);
				}
			}
			_awardArray.push(strArr);
						
			
		}
		/**
		 * 筛选出有多少个活动 
		 */		
		private var awardArr:Array;
		private function AwardInfo(arr:Array):void
		{
			awardArr = [] ;
			var i:int = 0 ; 
			var array:Array =[] 
			for(i; i<arr.length ; i++)
			{
				if(arr[i]!="#")
				{
					array.push(arr[i]) ; 
				}else
				{
					awardArr.push(array);
					array =[] ;
				}
			}
//			awardArr.sort(function (a:Array ,b:Array):int
//			{
//				return a[0]-b[0] ;
//			});
			
		}
		/*** 清除图片
		 */		
		private function ClearItem():void
		{
			var i :int = 0 ; 
			for( i ; i <viewGroup.col  * viewGroup.row ;  i++)
			{
				var mc:MovieClip = viewGroup.getItemByIndex( i ) ;
				if(mc["image"].source != "")
				{
					mc["image"].source = ""; 
				}
			}
		}
	
		/**
		 * 
		 * @param arr
		 * @param value
		 * @param count
		 * @return s
		 * 领取按钮的显示方式
		 * 
		 */
		private var taskOver:int  = -1 ;  
		private function showGain(value:int,row:int):void
		{
		
//			var mc:MovieClip = _group.getItemByIndex(_newIndex);
//			mc["over"] = value ;
//			taskOver =value ; 
//			var itemMCAward:MovieClip=_ui.item.getItemByIndex(row);
//
//			if(value==0)// 当前任务已经领取蛙完
//			{
//				itemMCAward["btn_1"].visible= true ; 
//				itemMCAward["btn_1"].gotoAndStop(2);
//			}else if(value==-1)// 条件不满足不显示
//			{
//				itemMCAward["btn_1"].visible= false ; 
//			}else//可以领取了
//			{
//				itemMCAward["btn_1"].visible= true ; 
//				itemMCAward["btn_1"].gotoAndStop(1);
//			}
		}
		/**
		 * 解析服务器发过来的 字符串
		 * @param value
		 * @return 
		 * 
		 */
		private function getStr(arr:Array):void
		{
			/***
			 * arr[2] == 2 开服到永久
			 * arr[2] == 1 name=*开服到开服第{@0:num}天的24点*
			 * arr[2] == 0 
			 * */
			
			getTimerStr(arr[2],arr,2);
			getTimerStr(arr[5],arr,5);
			
		}
		private function getTimerStr(value:int ,arr:Array,index:int):Array
		{
		
			var arrTime:Array=[];
			var arrlength:Array = [[]] ; 
			switch(value)
			{
				case 0:
					for(var i:uint=1;i<3;i++)
					{
						var str:String = arr[index+i].toString();
						arrTime.push(str.split("|"));
					}
					var j:uint  =0
					for(j;j<arrTime.length ;j++)
					{
						for(var k:uint = 0; k<5 ; k++)
						{
							arrlength[0].push(arrTime[j][k])
						}
					}
					if(index==2)
					{
						_ui.activitytime.htmlText  = StaticIni.getSwfLangStrVar("ActivitiesStr_1",arrlength[0]);
					}else
					{
						_ui.getAward.htmlText  	   = StaticIni.getSwfLangStrVar("ActivitiesStr_1",arrlength[0]);
					}
					break ;
				case 1:
					if(index==2)
					{
						_ui.activitytime.htmlText  =StaticIni.getSwfLangStrVar("UIString_1000621",[arr[3]]);
					}else
					{
						_ui.getAward.htmlText  =StaticIni.getSwfLangStrVar("UIString_1000621",[arr[6]]);
					}
					break ; 
				case 2:
					//name=*开服到永久*
					if(index==2)
					{
						_ui.activitytime.htmlText  = StaticIni.getSwfLangStr("UIString_1000620");
					}else
					{
						_ui.getAward.htmlText  = StaticIni.getSwfLangStr("UIString_1000620");
					}
					break ;
			}
			return arrTime ; 
		}
		/**
		 * 更新页数和最后一页的按钮数
		 * 有多少页每页多少个
		 */
		private function updatepageIndex(value:uint):Array
		{
			if(value==0)return []; 
			var pageIndex:uint = 0;
			var arr:Array = new Array(); 
			if(value/5>0)
			{
				pageIndex=value/5;
				var i:uint =0;0
				for(i;i<pageIndex;i++)
				{
					arr.push(5); 
				}
				if(value%5>0)
				{
					arr.push(value%5); 
				}
			}
			return arr 
		}
		/**
		 * bold 字体是否加粗
		 * color 字体颜色
		 */		
		private function setTextFormat(color:int,size:int=12 ,bold:Boolean=false):TextFormat
		{
			 var  _textformat:TextFormat= new TextFormat();
			 _textformat.font="宋体"; 
			 _textformat.bold = bold;
			 _textformat.color=color ; 
			 _textformat.size =  size ; 
			 
			 return _textformat
		}
		public function set getRewardCount(value:int):void
		{
			if(value>0)
			{
				ActivitesGroupLogic.getInstance().addEffect(31);
			}else if (value <=0)
			{
				ActivitesGroupLogic.getInstance().removeEffect(31);
			}
		}
		
		
		//生成Label 并存储到 数组里面
		private function setNxlabel(obj:Object):void
		{
			if(obj == null )return ;
			var text:NxText = new NxText (); 
			text.width=80 ; 
			text.wordWrap = true  ;
			text.x = 10;
			text.y = (307 -_ui.nxPanel.y)+ countRow*58; 
			text.htmlText = "" ; 
			text.htmlText = "<font color='0xffdfac'>" + obj["titleTxt1"]   + "</font>"; 
			text.setTextFormat(setTextFormat(0xffdfac));
			text.glowColor = 0x000000 ; 
			_ui.nxPanel.addView(text) ; 
			setHeigt();
			arrLabel.push(text);
			
		}
		//清空存储按钮的数组
		private function clearArrBtn():void
		{
			if(arrBtn == null )return ; 
			for(var j:int = 0; j<arrBtn.length ; j++)
			{
				(arrBtn[j] as NxButton).removeEventListener(MouseEvent.CLICK,getAwardHandler);
				_ui.nxPanel.removeView((arrBtn[j] as NxButton)) ;
				setHeigt();
			}
			if(arrBtn.length>0)
			{
				arrBtn.splice(0);
			}	
		}
		//清空存储 Label 的数组
		private function clearArrLabel():void
		{
			if(arrLabel == null )return ; 
			for(var i :int = 0; i<arrLabel.length ; i++)
			{
				(arrLabel[i] as NxText).htmlText = "" ; 
				(arrLabel[i] as NxText).htmlStr = "" ; 
				(arrLabel[i] as NxText).text  = ""  ;  
				_ui.nxPanel.removeView(arrLabel[i] as NxText);
				setHeigt();
			}
			if(arrLabel.length>0)
			{
				arrLabel.splice(0);
			}
		}
		//清空动态的线
		private function clearArrLine():void
		{
			if(arrLine == null)return ; 
			for(var i :int = 0; i<arrLine.length ; i++)
			{
				_ui.nxPanel.removeView(arrLine[i] as MovieClip);
				setHeigt();
			}
			if(arrLine.length>0)
			{
				arrLine.splice(0);
			}
		}
		//生成Btn(领取按钮)并存储到 数组里面
		private function setNxButton(obj:Object):void
		{
			if(obj == null )return ; 
			
			if(obj["BtnVisible"] == -1)
			{
				
			}else
			{
				var btn:NxButton = new NxButton (); 
				if (obj["BtnVisible"]==0)
				{
					btn.skin = "Button_41";
					btn.width = 75 ; 
					btn.height = 38; 
					btn.data.HandleProperties("ID",-1); 
					
				}else if (obj["BtnVisible"]==1||obj["BtnVisible"]>0)
				{
					btn.skin = "Button_40";
					btn.width = 75 ; 
					btn.height = 34; 
					btn.data.HandleProperties("ID",obj["ID"] ); 
				}
				btn.label = "" ;
				
				
				btn.x	= 140+45*5;  
				btn.y	= (315 -_ui.nxPanel.y)+ countRow*58; 
				
//				_ui.windowBG.addChildAt(btn,_ui.windowBG.numChildren-1);
				
				_ui.nxPanel.addView(btn);
				setHeigt();
				btn.addEventListener(MouseEvent.CLICK,getAwardHandler); 
				arrBtn.push(btn);
			}
		
		}
		private function setHeigt():void
		{
			_ui.nxPanel.viewWidth   = 	442;
			_ui.nxPanel.viewHeight  = 	375	; 
			_ui.nxPanel.width		=	442; 
			_ui.nxPanel.height		=	375 ;
		}
	}
}